*----------------------------------------------------------------------*
* 程序的事务代码: ZFIU028
* 程序名称:  供应商税号批量导入
* 作者       :  王鹏
* 时间        : 20250101
* 模块      : FI
* 负责人 :
* 描述 :
*
*
*
* 特殊特性:
*
*
*----------------------------------------------------------------------*
* 修改记录:
*作者      时间      描述
*-----------  --------  -----------------------------------------------*
*
*----------------------------------------------------------------------*
REPORT ZFIU028.
TABLES: LFA1,SSCRFIELDS.

TYPES:
  BEGIN OF TY_VENDOR_DATA,
    LIFNR TYPE LFA1-LIFNR,
    NAME1 TYPE LFA1-NAME1,
    STCD5 TYPE LFA1-STCD5,
  END OF TY_VENDOR_DATA,

  BEGIN OF TY_ALV_DATA,
    LIGHT TYPE ICONNAME, "信息灯列
    MSG   TYPE BAPIRET2-MESSAGE,

    LIFNR TYPE LFA1-LIFNR,
    NAME1 TYPE LFA1-NAME1,
    STCD5 TYPE LFA1-STCD5,
  END OF TY_ALV_DATA.

DATA:
  GR_TABLE       TYPE REF TO CL_SALV_TABLE,
  GT_VENDOR_DATA TYPE TABLE OF TY_VENDOR_DATA WITH HEADER LINE,
  GT_UPLOAD_DATA TYPE TABLE OF TY_VENDOR_DATA WITH HEADER LINE,
  GT_ALV_DATA    TYPE TABLE OF TY_ALV_DATA WITH HEADER LINE.

CONSTANTS:
  GC_BATCH_TEMPL_NAME  TYPE WWWDATATAB-OBJID VALUE 'ZFIU028_TMPL'.

SELECTION-SCREEN: BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-T01.
  SELECT-OPTIONS:
    S_LIFNR FOR LFA1-LIFNR,
    S_NAME1 FOR LFA1-NAME1,
    S_NAME2 FOR LFA1-NAME2,
    S_STCD5 FOR LFA1-STCD5.

SELECTION-SCREEN: END OF BLOCK BLK1.

SELECTION-SCREEN: BEGIN OF BLOCK BLK2 WITH FRAME TITLE TEXT-T02.
  PARAMETERS:
    P_FILE TYPE STRING,
    P_UPD  AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN: END OF BLOCK BLK2.

SELECTION-SCREEN FUNCTION KEY 1 .

INITIALIZATION.
  PERFORM FRM_INIT_DATA.

AT SELECTION-SCREEN.
  IF SSCRFIELDS-UCOMM EQ 'FC01'.
    PERFORM FRM_GET_DATA.
    PERFORM FRM_FILL_DATA_TO_EXCEL.
  ENDIF.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
  PERFORM FRM_GET_FILE.

START-OF-SELECTION.

  PERFORM FRM_GET_DATA_FROM_EXCEL.

  PERFORM FRM_PROCESS_DATA.

  PERFORM FRM_ALV_DISPLAY.

END-OF-SELECTION.

*&---------------------------------------------------------------------*
*& Form FRM_CHANGE_VENDOR_TAXNO
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      <-- GT_ALV_DATA
*&---------------------------------------------------------------------*
FORM FRM_CHANGE_VENDOR_TAXNO USING IV_STCD5 TYPE LFA1-STCD5 CHANGING CS_ALV_DATA TYPE TY_ALV_DATA.

  DATA:
    LT_RETURN          TYPE  TABLE OF BAPIRET2 WITH HEADER LINE,
    LV_BUSINESSPARTNER TYPE  BAPIBUS1006_HEAD-BPARTNER,
    LV_TAXTYPE         TYPE  BAPIBUS1006TAX-TAXTYPE,
    LV_TAXNUMBER       TYPE  BAPIBUS1006TAX-TAXNUMBER.

  LV_BUSINESSPARTNER = CS_ALV_DATA-LIFNR.
  LV_TAXNUMBER = CS_ALV_DATA-STCD5.
  LV_TAXTYPE = 'CN0'.

  IF IV_STCD5 IS INITIAL.
    CALL FUNCTION 'BAPI_BUPA_TAX_ADD'
      EXPORTING
        BUSINESSPARTNER = LV_BUSINESSPARTNER
        TAXTYPE         = LV_TAXTYPE
        TAXNUMBER       = LV_TAXNUMBER
      TABLES
        RETURN          = LT_RETURN[].

  ELSE.
    CALL FUNCTION 'BAPI_BUPA_TAX_CHANGE'
      EXPORTING
        BUSINESSPARTNER = LV_BUSINESSPARTNER
        TAXTYPE         = LV_TAXTYPE
        TAXNUMBER       = LV_TAXNUMBER
      TABLES
        RETURN          = LT_RETURN[].

  ENDIF.

  LOOP AT LT_RETURN WHERE TYPE = 'E' OR TYPE = 'A'.
    IF CS_ALV_DATA-MSG IS INITIAL.
      CS_ALV_DATA-MSG = LT_RETURN-MESSAGE.
    ELSE.
      CONCATENATE CS_ALV_DATA-MSG LT_RETURN-MESSAGE INTO CS_ALV_DATA-MSG SEPARATED BY ';'.
    ENDIF.
  ENDLOOP.
  IF SY-SUBRC = 0.

    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

    CS_ALV_DATA-LIGHT = ICON_RED_LIGHT.
  ELSE.

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

    CS_ALV_DATA-LIGHT = ICON_GREEN_LIGHT.
    CS_ALV_DATA-MSG = '供应商税号已更新'(t05).
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_PROCESS_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM FRM_PROCESS_DATA .
  DATA:
    LT_LFA1 TYPE TABLE OF TY_VENDOR_DATA WITH HEADER LINE.

  LOOP AT GT_UPLOAD_DATA.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        INPUT  = GT_UPLOAD_DATA-LIFNR
      IMPORTING
        OUTPUT = GT_UPLOAD_DATA-LIFNR.

    MODIFY GT_UPLOAD_DATA.
  ENDLOOP.

  SELECT
   LIFNR
   NAME1
   STCD5
   INTO CORRESPONDING FIELDS OF TABLE LT_LFA1
   FROM LFA1
    FOR ALL ENTRIES IN GT_UPLOAD_DATA
  WHERE LIFNR = GT_UPLOAD_DATA-LIFNR
    AND LOEVM = SPACE
    AND SPERR = SPACE
    AND SPERM = SPACE.

  SORT LT_LFA1 BY LIFNR.
  LOOP AT GT_UPLOAD_DATA.
    CLEAR GT_ALV_DATA.
    MOVE-CORRESPONDING GT_UPLOAD_DATA TO GT_ALV_DATA.

    CLEAR LT_LFA1.
    READ TABLE LT_LFA1 WITH KEY
      LIFNR = GT_UPLOAD_DATA-LIFNR
      BINARY SEARCH.
    IF SY-SUBRC <> 0.
      GT_ALV_DATA-LIGHT = ICON_RED_LIGHT.
      GT_ALV_DATA-MSG = '供应商不存在或已冻结'(M02).

    ELSE.
      IF GT_UPLOAD_DATA-STCD5 = LT_LFA1-STCD5.
        GT_ALV_DATA-LIGHT = ICON_YELLOW_LIGHT.
        GT_ALV_DATA-MSG = '供应商税号和批导人税号一致，无需调整'(M03).

      ELSE.
        IF P_UPD IS INITIAL.
          GT_ALV_DATA-LIGHT = ICON_GREEN_LIGHT.
          GT_ALV_DATA-MSG = '可调整'(M04).
        ELSE.
          PERFORM FRM_CHANGE_VENDOR_TAXNO USING LT_LFA1-STCD5 CHANGING GT_ALV_DATA.

        ENDIF.
      ENDIF.
    ENDIF.

    APPEND GT_ALV_DATA.
  ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_GET_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM FRM_GET_DATA .

  REFRESH: GT_VENDOR_DATA.

  SELECT
    LIFNR
    NAME1
    STCD5
    INTO CORRESPONDING FIELDS OF TABLE GT_VENDOR_DATA
    FROM LFA1
   WHERE LIFNR IN S_LIFNR
     AND NAME1 IN S_NAME1
     AND NAME2 IN S_NAME2
     AND STCD5 IN S_STCD5
     AND LOEVM = SPACE
     AND SPERR = SPACE
     AND SPERM = SPACE.

  IF SY-SUBRC <> 0.
    MESSAGE '无数据，请检查查询条件'(M01) TYPE 'E'.
  ENDIF.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form frm_init_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM FRM_INIT_DATA .
  DATA LV_FUNCTXT TYPE SMP_DYNTXT.
  LV_FUNCTXT-ICON_ID       = ICON_EXPORT.
  LV_FUNCTXT-QUICKINFO     = '供应商下载'(F01).
  LV_FUNCTXT-ICON_TEXT     = '供应商下载'(F01).

  SSCRFIELDS-FUNCTXT_01 = LV_FUNCTXT.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form FRM_FILL_DATA_TO_EXCEL
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM FRM_FILL_DATA_TO_EXCEL .

  DATA:
    LV_TITLE     TYPE STRING,
    LV_DIR       TYPE STRING,
    LV_ROW       TYPE I,
    LV_COLUMN    TYPE I,
    LR_DATA_DESC TYPE REF TO CL_ABAP_DATADESCR,
    LV_ABAP_TYPE TYPE  ABAP_TYPEKIND.

  DATA LS_KEY TYPE WWWDATATAB.
  DATA LT_MIME TYPE TABLE OF W3MIME.
  DATA LV_XSTRING TYPE XSTRING.
  DATA LO_READER TYPE REF TO ZIF_EXCEL_READER.
  DATA LO_EXCEL_WRITER TYPE REF TO ZIF_EXCEL_WRITER.
  DATA LO_WORKSHEET TYPE REF TO ZCL_EXCEL_WORKSHEET.
  DATA LV_FILE TYPE XSTRING.
  DATA LV_BYTECOUNT TYPE I.
  DATA LT_FILE_TAB  TYPE SOLIX_TAB.

  SELECT SINGLE
    A~RELID,
    A~OBJID,
    B~VALUE
    FROM WWWDATA AS A
    LEFT JOIN WWWPARAMS AS B
      ON A~RELID = B~RELID
     AND A~OBJID = B~OBJID
     AND B~NAME EQ 'filesize'
   WHERE A~SRTF2 = 0
     AND A~RELID = 'MI'
     AND A~OBJID = @GC_BATCH_TEMPL_NAME
     INTO @DATA(LS_TEMPT).
  IF SY-SUBRC <> 0 .
    MESSAGE TEXT-M03 TYPE 'E'.
    RETURN.
  ENDIF.

  LV_TITLE = '请选择数据下载目录'(T03).

  CALL METHOD CL_GUI_FRONTEND_SERVICES=>DIRECTORY_BROWSE
    EXPORTING
      WINDOW_TITLE         = LV_TITLE
    CHANGING
      SELECTED_FOLDER      = LV_DIR
    EXCEPTIONS
      CNTL_ERROR           = 1
      ERROR_NO_GUI         = 2
      NOT_SUPPORTED_BY_GUI = 3
      OTHERS               = 4.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE 'E' NUMBER SY-MSGNO
               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    RETURN.
  ENDIF.

  IF LV_DIR IS INITIAL.
    RETURN.
  ENDIF.

  LS_KEY = VALUE #( RELID = LS_TEMPT-RELID OBJID = LS_TEMPT-OBJID ).
  CALL FUNCTION 'WWWDATA_IMPORT'
    EXPORTING
      KEY               = LS_KEY
    TABLES
      MIME              = LT_MIME
    EXCEPTIONS
      WRONG_OBJECT_TYPE = 1
      IMPORT_ERROR      = 2
      OTHERS            = 3.
  IF SY-SUBRC <> 0.
    MESSAGE TEXT-M04 TYPE 'E'.
    RETURN.
  ENDIF.

  CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
    EXPORTING
      INPUT_LENGTH = CONV I( LS_TEMPT-VALUE )
    IMPORTING
      BUFFER       = LV_XSTRING
    TABLES
      BINARY_TAB   = LT_MIME
    EXCEPTIONS
      FAILED       = 1
      OTHERS       = 2.
  IF SY-SUBRC <> 0.
    MESSAGE TEXT-M04 TYPE 'E'.
    RETURN.
  ENDIF.

  CHECK LV_XSTRING IS NOT INITIAL.

  TRY .
      CREATE OBJECT LO_READER TYPE ZCL_EXCEL_READER_2007.
      DATA(LO_EXCEL) = LO_READER->LOAD( I_EXCEL2007 = LV_XSTRING ).
      LO_EXCEL->SET_ACTIVE_SHEET_INDEX( 1 ).
      LO_WORKSHEET = LO_EXCEL->GET_ACTIVE_WORKSHEET( ).

      "填充数据
      LOOP AT GT_VENDOR_DATA.
        LV_ROW = SY-TABIX + 1.
        DO.
          ASSIGN COMPONENT SY-INDEX OF STRUCTURE GT_VENDOR_DATA TO FIELD-SYMBOL(<FS_FIELD>).
          IF SY-SUBRC <> 0.
            EXIT.
          ENDIF.

          IF <FS_FIELD> IS INITIAL."为空的不再赋值
            CONTINUE.
          ENDIF.

          LV_COLUMN =  SY-INDEX.
          LR_DATA_DESC ?=  CL_ABAP_TYPEDESCR=>DESCRIBE_BY_DATA( <FS_FIELD> ).
          LV_ABAP_TYPE = LR_DATA_DESC->GET_DATA_TYPE_KIND( <FS_FIELD> ).

          LO_WORKSHEET->SET_CELL( IP_COLUMN    = LV_COLUMN
                                  IP_ROW       = LV_ROW
                                  IP_VALUE     = <FS_FIELD>
                                  IP_ABAP_TYPE = COND #( WHEN LV_ABAP_TYPE IS NOT INITIAL THEN LV_ABAP_TYPE ELSE CL_ABAP_TYPEDESCR=>TYPEKIND_STRING ) ).
        ENDDO.
      ENDLOOP.



      CREATE OBJECT LO_EXCEL_WRITER TYPE ZCL_EXCEL_WRITER_2007.
      LV_FILE = LO_EXCEL_WRITER->WRITE_FILE( LO_EXCEL ).

    CATCH ZCX_EXCEL INTO DATA(LR_CX_EXCEL).

      MESSAGE LR_CX_EXCEL->GET_TEXT( ) TYPE 'E'.
      RETURN.
  ENDTRY.

  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
    EXPORTING
      BUFFER        = LV_FILE
    IMPORTING
      OUTPUT_LENGTH = LV_BYTECOUNT
    TABLES
      BINARY_TAB    = LT_FILE_TAB.

  LV_DIR = LV_DIR && TEXT-T04 && SY-DATUM &&  '.xlsx'. "'_' && SY-UZEIT &&

  CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD(
    EXPORTING
      BIN_FILESIZE            = LV_BYTECOUNT
      FILENAME                = LV_DIR
      FILETYPE                = 'BIN'
    CHANGING
      DATA_TAB                = LT_FILE_TAB
    EXCEPTIONS
      FILE_WRITE_ERROR        = 1
      NO_BATCH                = 2
      GUI_REFUSE_FILETRANSFER = 3
      INVALID_TYPE            = 4
      NO_AUTHORITY            = 5
      UNKNOWN_ERROR           = 6
      HEADER_NOT_ALLOWED      = 7
      SEPARATOR_NOT_ALLOWED   = 8
      FILESIZE_NOT_ALLOWED    = 9
      HEADER_TOO_LONG         = 10
      DP_ERROR_CREATE         = 11
      DP_ERROR_SEND           = 12
      DP_ERROR_WRITE          = 13
      UNKNOWN_DP_ERROR        = 14
      ACCESS_DENIED           = 15
      DP_OUT_OF_MEMORY        = 16
      DISK_FULL               = 17
      DP_TIMEOUT              = 18
      FILE_NOT_FOUND          = 19
      DATAPROVIDER_EXCEPTION  = 20
      CONTROL_FLUSH_ERROR     = 21
      NOT_SUPPORTED_BY_GUI    = 22
      ERROR_NO_GUI            = 23
      OTHERS                  = 24 ).
  IF SY-SUBRC <> 0.
    "ES_RETURN-MSGTS = 'E'.
  ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_GET_DATA_FROM_EXCEL
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM FRM_GET_DATA_FROM_EXCEL .
  DATA:
    LO_READER    TYPE REF TO ZIF_EXCEL_READER,
    LO_EXCEL     TYPE REF TO ZCL_EXCEL,
    LO_WORKSHEET TYPE REF TO ZCL_EXCEL_WORKSHEET,
    LT_CELL      TYPE ZEXCEL_T_CELL_DATA.

  FIELD-SYMBOLS: <FS_FIELD> TYPE ANY.

  REFRESH GT_UPLOAD_DATA[].

  IF P_FILE IS INITIAL.
    MESSAGE '请选择供应商税号批导人文件'(M02) TYPE 'S' DISPLAY LIKE 'E'.
    LEAVE LIST-PROCESSING.
  ENDIF.

  TRY .
      CREATE OBJECT LO_READER TYPE ZCL_EXCEL_READER_2007.
      LO_EXCEL = LO_READER->LOAD_FILE( I_FILENAME = P_FILE ).
      LO_EXCEL->SET_ACTIVE_SHEET_INDEX( 1 ).
      LO_WORKSHEET = LO_EXCEL->GET_ACTIVE_WORKSHEET( ).

      LT_CELL = LO_WORKSHEET->SHEET_CONTENT.

    CATCH ZCX_EXCEL INTO DATA(LR_CX_EXCEL).

      "MESSAGE LR_CX_EXCEL->GET_TEXT( ) TYPE 'S' DISPLAY LIKE 'E'.
      MESSAGE '读取文件出错，请关闭excel文件后重试'(M03) TYPE 'S' DISPLAY LIKE 'E'.
      LEAVE LIST-PROCESSING.
  ENDTRY.

  "删除表头数据
  DELETE LT_CELL WHERE CELL_ROW <= 1.
  IF LT_CELL[] IS INITIAL.
    MESSAGE '文件中无有效数据，请检查'(M04) TYPE 'S' DISPLAY LIKE 'E'.
    LEAVE LIST-PROCESSING.
  ENDIF.

  LOOP AT LT_CELL INTO DATA(LS_CELL).
    "对字段赋值，内表字段顺序要和Excel完全一致
    ASSIGN COMPONENT LS_CELL-CELL_COLUMN OF STRUCTURE GT_UPLOAD_DATA TO <FS_FIELD>.
    <FS_FIELD> = LS_CELL-CELL_VALUE.

    AT END OF CELL_ROW.
      APPEND GT_UPLOAD_DATA.
      CLEAR GT_UPLOAD_DATA.
    ENDAT.
  ENDLOOP.

  "删除没有税号的数据
  DELETE GT_UPLOAD_DATA WHERE STCD5 IS INITIAL.

  IF GT_UPLOAD_DATA[] IS INITIAL.
    MESSAGE '文件中无有效数据，请检查'(M05) TYPE 'S' DISPLAY LIKE 'E'.
    LEAVE LIST-PROCESSING.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_ALV_DISPLAY
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM FRM_ALV_DISPLAY .
  DATA:
    LR_DISPLAY   TYPE REF TO CL_SALV_DISPLAY_SETTINGS,
    LR_FUNC_LIST TYPE REF TO CL_SALV_FUNCTIONS_LIST,
    "LR_EVENTS    TYPE REF TO CL_SALV_EVENTS,
    LR_EVENTS    TYPE REF TO CL_SALV_EVENTS_TABLE,
    LR_SELECTS   TYPE REF TO CL_SALV_SELECTIONS,
    LR_COLUMNS   TYPE REF TO CL_SALV_COLUMNS_TABLE,
    LR_COLUMN    TYPE REF TO CL_SALV_COLUMN_TABLE,
    LR_LAYOUT    TYPE REF TO CL_SALV_LAYOUT,
    LS_DDIC      TYPE SALV_S_DDIC_REFERENCE,
    LS_KEY       TYPE SALV_S_LAYOUT_KEY.

  TRY.
      CL_SALV_TABLE=>FACTORY(
        IMPORTING
          R_SALV_TABLE = GR_TABLE
        CHANGING
          T_TABLE      = GT_ALV_DATA[]
      ).
    CATCH CX_SALV_MSG.
  ENDTRY.

  "设置列Lable
  LR_COLUMNS = GR_TABLE->GET_COLUMNS( ).
  LR_COLUMNS->SET_OPTIMIZE( 'X' ).
  LR_COLUMNS->SET_KEY_FIXATION( 'X' ).


  "显示设置
  LR_DISPLAY = GR_TABLE->GET_DISPLAY_SETTINGS( ).
  LR_DISPLAY->SET_STRIPED_PATTERN( 'X' ). "设置颜色间隔显示

  "设置选择模式
  LR_SELECTS = GR_TABLE->GET_SELECTIONS( ).
  LR_SELECTS->SET_SELECTION_MODE( CL_SALV_SELECTIONS=>IF_SALV_C_SELECTION_MODE~CELL ).

  "STAUTS ALV 标准功能
  LR_FUNC_LIST = GR_TABLE->GET_FUNCTIONS( ).
  LR_FUNC_LIST->SET_ALL( 'X' ).

  "设置ALV自定义按钮功能
*  GR_TABLE->SET_SCREEN_STATUS(
*    PFSTATUS      = '9000'
*    REPORT        = SY-REPID
*    SET_FUNCTIONS = GR_TABLE->C_FUNCTIONS_ALL ).

  "按钮事件接受
*  LR_EVENTS = GR_TABLE->GET_EVENT( ).
*  CREATE OBJECT GR_EVENTS_HANDLER.
*  SET HANDLER GR_EVENTS_HANDLER->ON_USER_COMMAND FOR LR_EVENTS.
*  SET HANDLER GR_EVENTS_HANDLER->ON_LINK_CLICK FOR LR_EVENTS.


  "打开Layout保存功能
  LR_LAYOUT = GR_TABLE->GET_LAYOUT( ).
  LS_KEY-REPORT = SY-REPID.
  LR_LAYOUT->SET_KEY( LS_KEY ).
  LR_LAYOUT->SET_DEFAULT( ABAP_TRUE ).
  LR_LAYOUT->SET_SAVE_RESTRICTION( IF_SALV_C_LAYOUT=>RESTRICT_NONE ).

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'LIGHT' ).
      LR_COLUMN->SET_KEY( 'X' ).
      LR_COLUMN->SET_ICON( 'X' ).
      LR_COLUMN->SET_SHORT_TEXT( '状态灯'(H01) ).
      LR_COLUMN->SET_MEDIUM_TEXT( '状态灯'(H01) ).
      LR_COLUMN->SET_LONG_TEXT( '状态灯'(H01) ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'MSG' ).
      LR_COLUMN->SET_KEY( 'X' ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  TRY .
      LR_COLUMN  ?= LR_COLUMNS->GET_COLUMN( 'LIFNR' ).
      "LR_COLUMN->SET_CELL_TYPE( IF_SALV_C_CELL_TYPE=>HOTSPOT ).
      LR_COLUMN->SET_KEY( 'X' ).
    CATCH CX_SALV_NOT_FOUND.
  ENDTRY.

  GR_TABLE->DISPLAY( ).
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_GET_FILE
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM FRM_GET_FILE .
  DATA:
    LT_FILE_TABLE TYPE FILETABLE,
    LS_FILE_TABLE TYPE LINE OF FILETABLE,
    LV_RC         TYPE I.

  CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
    EXPORTING
      WINDOW_TITLE            = 'Select Source Excel File'
*     default_extension       = ''
*     default_filename        =
      FILE_FILTER             = 'Excel Files (*.xlsx)|*.xlsx'
*     with_encoding           =
*     initial_directory       =
*     multiselection          =
    CHANGING
      FILE_TABLE              = LT_FILE_TABLE
      RC                      = LV_RC
*     user_action             =
*     file_encoding           =
    EXCEPTIONS
      FILE_OPEN_DIALOG_FAILED = 1
      CNTL_ERROR              = 2
      ERROR_NO_GUI            = 3
      NOT_SUPPORTED_BY_GUI    = 4
      OTHERS                  = 5.
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  READ TABLE LT_FILE_TABLE INTO LS_FILE_TABLE INDEX 1.
  IF SY-SUBRC = 0.
    P_FILE = LS_FILE_TABLE-FILENAME.
  ENDIF.
ENDFORM.
